/**
 * 
 */
package com.fox.webapp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.fox.webapp.domain.LoginLog;
import com.fox.webapp.domain.Person;
import com.fox.webapp.persistent.LoginLogRepository;
import com.fox.webapp.persistent.PersonRepository;
import com.fox.webapp.service.ILoginLogService;

/**
 * @author Yockii
 *
 */
@Service
public class LoginLogService implements ILoginLogService {

	@Autowired
	private LoginLogRepository loginLogRepository;
	
	@Autowired
	private PersonRepository personRepository;
	
	/* (non-Javadoc)
	 * @see com.fox.webapp.service.ILoginLogService#getMyLoginLog(com.fox.webapp.domain.Person, int, int)
	 */
	@Override
	public Page<LoginLog> getMyLoginLog(Person p, int page, int length) {
		if(p == null) return null;
		return loginLogRepository.findByUsername(p.getUsername(), new PageRequest(page, length, Direction.DESC, "time"));
	}

}
